import { Vue, Component } from "vue-property-decorator";
import store from "@/store";

export const isTest = () => {
    return __DEV__;
}

export interface TokenDto {
    id: string;
    sig: string;
}


@Component
export class UserHelper extends Vue {
    token: TokenDto | null = null;
    isLogin = false;

    clearLoginInfo() {
        this.setToken(null);
    }

    setLoginInfo(data: TokenDto | null) {
        this.setToken(data);
    }

    setToken(token: TokenDto | null) {
        this.token = token;
        store.commit("token", token);
    }

    getToken() {
        if (!this.token) {
            this.token = store.getters.token;
        }
        return this.token;
    }

    logout() {
        this.clearLoginInfo();
        this.$pager.navigateTo("Login");
    }
}
